//
//  citySort.m
//  AIMTableViewIndexBarExample
//
//  Created by 李荃荃 on 14-10-24.
//  Copyright (c) 2014年 AllInMobile. All rights reserved.
//

#import "citySort.h"

@implementation citySort


- (NSMutableArray *)setSrot:(NSString *)ask
{
    WeiPlist *plist = [[WeiPlist alloc] init];
    
//    NSArray *pathrray = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
//    NSString *path = [pathrray objectAtIndex:0];
//    NSString *filepath = [path stringByAppendingPathComponent:@"weather_cities.plist"];
    NSDictionary *rootArray = [plist dictionaryData:@"weather_cities"];
    NSMutableArray *cities = [rootArray objectForKey:@"cities"];
    
    NSMutableArray *arr = [NSMutableArray array];
    for (NSDictionary *dic in cities) {
        NSString *string = [dic objectForKey:@"city"];
        [arr addObject:string];
    }
    
    [arr sortUsingSelector:@selector(compare:)];
    
    NSMutableArray *cityArr = [NSMutableArray array];
    for (NSString *string in arr) {
        for (NSDictionary *dic in cities) {
            if ([string isEqualToString:[dic objectForKey:@"city"]]) {
                [cityArr addObject:dic];
            }
        }
    }
    

    
   
        NSMutableArray *newArr = [NSMutableArray array];
        for (NSDictionary *dic in cityArr) {
            if ([[dic objectForKey:@"city"] hasPrefix:ask]) {
                [newArr addObject:dic];
            }
        }
            NSMutableArray *newArr1 = [NSMutableArray array];
            for (NSDictionary *dic in newArr) {
                NSString *str = [dic objectForKey:@"name"];
                [newArr1 addObject:str];
            }
      return newArr1;
}

- (NSMutableArray *)hotCities
{
    NSArray *pathrray = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *path = [pathrray objectAtIndex:0];
    NSString *filepath = [path stringByAppendingPathComponent:@"weather_cities.plist"];
    NSDictionary *rootArray = [NSDictionary dictionaryWithContentsOfFile:filepath];
    NSMutableArray *cities = [rootArray objectForKey:@"hot_cities"];
    return cities;
}


@end
